package com.leaf.u_spring.chapter03;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MagicBeanConfig {

	/**
	 * 条件化创建bean
	 * 
	 * @Conditional中给定了一个Class，它指明了条件MagicExistsConditional
	 * @Conditional会通过Condition接口进行条件对比
	 * 设置给@Conditional的类可以是任意实现了Condition接口的类型
	 * 如果matches返回true,就创建@Conditional注解的类，否则不创建
	 * @return
	 */
	@Bean
	@Conditional(MagicExistsConditional.class)
	public MagicBean magicBean(){
		return new MagicBean();
	}
	
}
